import config from '@/commom/config.js';

export const http = (option) => {
	//获取本地存储的token
	const token = uni.getStorageSync('userinfo').token
	//需要验证身份的请求头
	const header_tmp ={
		"Authorization":token
	}
	//需要验证身份和上传文件的请求头
	const header_tpms = {
		"Authorization":token,
		"Content-Type":"multipart/form-data"
	}
	//发布文章专属请求头
	const header_tpmss = {
		"Authorization":token,
		'Content-type': 'application/x-www-form-urlencoded',
	}
	return new Promise((resolve, reject) => {
		uni.request({
			url: config.BASE_URL+option.url,
			data:option.data || '',
			header:option.header_type==1?header_tmp:option.header_type==2?header_tpms:option.header_type==3?header_tpmss:option.header,
			method:option.method || 'GET',
			success: res => {
				resolve(res.data);
			},
			fail: err => {
				reject(err);
			}
		});
	});
}